﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace machine_registration.Helpers
{
    public static class EnumExtensions
    {
        /// <summary>
        /// 获取枚举值的Description特性描述
        /// </summary>
        public static string GetDescription(this Enum value)
        {
            return value.GetType()
                       .GetMember(value.ToString())
                       .FirstOrDefault()
                       ?.GetCustomAttribute<DescriptionAttribute>()
                       ?.Description
                    ?? value.ToString();
        }
    }
}
